package com.wfs.myapp.controller;

import com.wfs.myapp.common.ApiResult;
import com.wfs.myapp.common.Constant;
import com.wfs.myapp.entity.domain.AiTalk;
import com.wfs.myapp.entity.dto.req.bk.AiTalkReqDto;
import com.wfs.myapp.service.AIService;
import com.wfs.myapp.utils.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/ai")
@Api(value = "百度AI API", tags = "百度AI API")
@Slf4j
public class AIController {

    @Autowired
    private AIService aiService;


    @PostMapping("/talk")
    @ApiOperation(value = "ai对话")
    public ApiResult<String> msgSend(@RequestBody AiTalkReqDto aiTalkReqDto,
                                    HttpServletRequest request
                                     ) {
        Long userId = JwtUtil.getUserId(request.getHeader(Constant.AUTHORIZATION));
        return aiService.talkAI(aiTalkReqDto.getMessage(), userId);
    }

    @GetMapping("/talkSessionHisList")
    @ApiOperation(value = "ai 1个session的对话记录")
    public ApiResult<List<AiTalk>> talkSessionHisList(HttpServletRequest request
    ) {
        Long userId = JwtUtil.getUserId(request.getHeader(Constant.AUTHORIZATION));
        return aiService.sessionHisList(userId);
    }


}
